package com.lagou.gateway.util;

import com.lagou.gateway.ResponseCodeEnum;

public class StatusCodeConvert {
    public static Integer convertCode(Object codeObject) {
        Integer code = ResponseCodeEnum.SUCCESS;

        if (code == null) {
            code = ResponseCodeEnum.STATUS_UNKNOWN;
        } else if (codeObject instanceof Integer
                && (Integer) codeObject != 200) {
            code = ResponseCodeEnum.BUSINESS_FAIL;
        } else if (codeObject instanceof String
                && !"SYS.SUCCESS".equals(codeObject)) {
            try {
                code = Integer.parseInt(String.valueOf(codeObject));
            } catch (Exception e) {
                code = ResponseCodeEnum.BUSINESS_FAIL;
            }
        }

        return code;
    }
}
